const jwt = require('jsonwebtoken')
const { JWTSECRET } = require("../../config/index")
const isUnauthorized = (token) => {
    return new Promise((resolve, reject) => {
        jwt.verify(token, JWTSECRET, (err, data) => {
            if (err && err.message === 'invalid token') resolve(false)
            if (err && err.message === 'jwt expired') resolve(false)
            resolve({
                userAccount: data.userAccount
            })
        })
    })
}
module.exports = {
    isUnauthorized
}